package com.chen.nio.zerocopy;

import java.io.DataInputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class OldIOServer {

    public static void main(String[] args) throws Exception {
        ServerSocket ss = new ServerSocket(8989);
        while (true) {
            //accept方法是阻塞的，该方法会监听客户端的连接并且接受socket
            Socket socket = ss.accept();
            System.out.println("server start......");
            DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
            byte[] buffer = new byte[1024];
            int len = 0;
            long startTime = System.currentTimeMillis();
            while ((len = dataInputStream.read(buffer)) != -1) {
            }
            long endTime = System.currentTimeMillis();
            System.out.println("耗费的时长：" + (endTime - startTime));
        }

    }

}
